package com.lz.football.module.bag.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.BagEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	import com.liangzhong.model.type.OtherGoodType;
	
	import common.item.GoodsItem;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.Alert;
	import lz.controls.events.ListEvent;
	import lz.controls.managers.TipsManager;

	/**
	 *背包item 
	 * @author lake
	 * 
	 */	
	public class BagItem extends GoodsItem
	{
		
		public function BagItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
		}
		/**
		 *设置获取锁定状态 
		 * @param value
		 * 
		 */		
		public function set isLock(value :Boolean):void
		{
			if(value)
			{
				this.addChild(lockMc);
				lockMc.x = (44 - lockMc.width)/2;
				lockMc.y = (50 - lockMc.height)/2;
				lockMc.alpha = .7;
				this.buttonMode = true;
				_data = null;
				DisplayObjectUtil.removeAllChildren(container);
				addLockEventListener();
			}
			else
			{
				if(lockMc && lockMc.parent)
				{
					lockMc.parent.removeChild(lockMc);
				}
				this.buttonMode = false;
				removeLockEventListener();
			}
		}
		public function get isLock():Boolean
		{
			return _isLock;
		}
		/**
		 * 选择
		 * 
		 */		
		override public function select():void
		{
			if(selectMc)
			{
				this.addChild(selectMc);
				selectMc.x = -2.3;
				selectMc.y = -0.5
			}
		}
		/**
		 * 
		 * 去除选择
		 */		
		override public function unSelect():void
		{
			if(selectMc && selectMc.parent)
			{
				selectMc.parent.removeChild(selectMc);
			}
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		override public function initUI(view:Object=null):void
		{
			super.initUI();
			
			lockMc = Reflection.createInstance("com.football.module.bag.LockSkin");
			this.doubleClickEnabled = true;
		}
		/**
		 * 添加事件
		 * 
		 */		
		override public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.addEventListener(MouseEvent.CLICK,onClickHandler);
			this.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		override protected function onOverHandler(e :MouseEvent):void
		{
			if(_data == null)return;
			if(_data.type == GoodsType.PLAYERCARD)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPS,_data,15,15,false);
			}
			else
			{
				TipsManager.show(TipsConst.BASETIPS,{tip:_data.tipsInfo},15,15,false);
			}
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		override protected function onOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 * 点击 
		 * @param e
		 * 
		 */		
		override protected function onClickHandler(e :MouseEvent):void
		{
			if(_data == null)
			{
				return;
			}
			this.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK,true));
		}
		/**
		 *双击使用 
		 * @param e
		 * 
		 */		
		override protected function onDoubleClickHandler(e :MouseEvent):void
		{
			if(_data==null)return;
			AppEventDispatcher.getInstance().dispatchEvent(new BagEvent(BagEvent.USE_ITEM,_data));
			TipsManager.hide();
		}
		/**
		 * 删除事件
		 * 
		 */		
		override public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.removeEventListener(MouseEvent.CLICK,onClickHandler);
			this.removeEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 *添加锁定事件 
		 * 
		 */		
		private function addLockEventListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onLockClickHandler);
		}
		/**
		 *点击锁 提示开格子 
		 * @param e
		 * 
		 */		
		private function onLockClickHandler(e :MouseEvent):void
		{
			var cash :int = AppData.getInstance().bagDataManager.bagInfo.needCash;
			var userCash :int = AppData.getInstance().clubDatamanager.clubInfo.cashpoint;
			var info :String;
			if(cash > userCash)
			{
				info = "消耗"+cash+"点卷可增加5格仓库位置。现有点券不足，是否前往充值?";
				Alert.noCashAlert(info);
			}
			else
			{
				info = "是否消费"+ cash +"点券额外增加5格仓库位置？";
				Alert.show(info,"",Alert.YES|Alert.NO,GlobalDef.AlertContainer,closeLockAlertHandler);
			}
		}
		/**
		 * 
		 * 关闭开格子确认面板
		 */		
		private function closeLockAlertHandler(cType :int):void
		{
			if(cType == Alert.YES)
			{
				this.dispatchEvent(new BagEvent(BagEvent.OPEN_CELLS,null,true));
			}
		}
		/**
		 *删除锁定事件 
		 * 
		 */		
		private function removeLockEventListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,onLockClickHandler);
		}
		/**
		 * 销毁
		 * 
		 */		
		override public function destroyView():void
		{
			super.destroyView();
			removeEvtListener();
			removeLockEventListener();
			_data = null;
		}
	}
}